﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using Caliburn.Micro;

namespace Agnes.Core
{
    /// <summary>
    /// DX文档基类
    /// </summary>
    public abstract class DocumentPanelBase<T> : ScreenBase<T> ,IDocumentPanel where T : ModelBase<T>
    {
        public DocumentPanelBase(T model)
        {
            Model = model;
            this.IsVaild = Model.IsValid;
            this.IsDirty = Model.IsDirty;
            Model.PropertyChanged += (sender, args) =>
                                         {
                                             this.IsVaild = Model.IsValid;
                                             this.IsDirty = Model.IsDirty;
                                         };
        }

        public virtual object Content
        {
            get { return GetView(this); }
        }

        private string _caption = "";
        public string Caption
        {
            get { return base.DisplayName; }
            set
            {
                base.DisplayName = value;
                NotifyOfPropertyChange(() => Caption);
            }
        }

        private Image _captionImage = null;
        public virtual Image CaptionImage
        {
            get { return _captionImage; }
            set
            {
                _captionImage = value;
                NotifyOfPropertyChange(() => CaptionImage);
            }
        }

        private bool _isDirty = false;
        public bool IsDirty
        {
            get
            {
                return _isDirty;
            }
            set
            {
                _isDirty = value;
                NotifyOfPropertyChange(() => IsDirty);
            }
        }

        private bool _isVaild = true;
        public bool IsVaild
        {
            get { return _isVaild; }
            set
            {
                _isVaild = value;
                NotifyOfPropertyChange(() => IsVaild);
            }
        }

        public abstract void Save();
        public abstract void Cancel();
        public abstract void PreViewClose(object sender, CancelEventArgs e);
    }
}